package cn.gz.sboot31.controller;

import cn.gz.sboot31.entity.User;
import cn.gz.sboot31.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/reg")
    public String reg(User user){
        String pwd = userMapper.selectByUsername(user.getUsername());
        if(pwd==null){//查不到，说明可以使用
            userMapper.insert(user);
            return "注册成功";
        }
        return "用户被占用，注册失败";
    }
    @RequestMapping("/login")
    public String login(User user){
        String pwd = userMapper.selectByUsername(user.getUsername());
        if(pwd==null){
            return "查无此人";
        }
        if(user.getPassword().equals(pwd)){
            return "登录成功";
        }
        return "密码错误";
    }
}
